package Java.BlackHorse.IO.ConvertStream;

import java.io.*;
import java.nio.charset.Charset;

public class IODemo2 {
    /*
    * 转换流
    * */
    public static void main(String[] args) throws IOException {
      /*
       InputStreamReader isr = new InputStreamReader(new FileInputStream("IO\\ConvertStream\\gqlxc.txt"),"UTF-8");
       OutputStreamWriter osr = new OutputStreamWriter(new FileOutputStream("IO\\ConvertStream\\gqlxc2.txt"),"GBK");

       int ch;
       while((ch = isr.read()) != -1){
           osr.write((char)ch);
       }

       osr.close();
       isr.close();
       */

        //替代方案
        FileReader fr = new FileReader("IO\\ConvertStream\\gqlxc.txt", Charset.forName("UTF-8"));
        FileWriter fw = new FileWriter("IO\\ConvertStream\\gqlxc2.txt",Charset.forName("GBK"));
        int ch;
        while((ch = fr.read()) != -1){
            fw.write(ch);
        }

        fw.close();
        fr.close();

    }
}
